﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace Public_Class_Library
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class ExFilter : IExceptionFilter
    {
        private readonly ILogger<ExFilter> _logger;

        public ExFilter(ILogger<ExFilter> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 异常过滤
        /// </summary>
        /// <param name="context">异常上下文</param>
        public void OnException(ExceptionContext context)
        {
            _logger.LogError("异常过滤器报错：" + context.Exception.StackTrace);
        }
    }
}
